#include <cppunit/config/SourcePrefix.h>

#include "RelationshipTable.h"
#include "RelationshipType.h"
#include "RelationshipArgumentType.h"
#include "TestRelationshipTable.h"

void RelationshipTableTest::setUp() {
	std::cout << "Test RelationshipTable setUp()\n";
}

void RelationshipTableTest::tearDown() {
}

// Registers the fixture into the 'registry'
CPPUNIT_TEST_SUITE_REGISTRATION( RelationshipTableTest );

// method to test the constructor
void RelationshipTableTest::testConstructor() {
	// Just to ensure it does not produce errors
	RelationshipTable relTable;
}

// method to test the validation functions of the RelationshipTable
void RelationshipTableTest::testValidationFunctions() {
	// Upon instantiation of the RelationshipTable,
	// it should be initialized with all the valid RelationshipTypes and their arguments
	RelationshipTable relTable;

	// Add a few valid arguments anyway (even though relTable should be initialized by itself
	std::map<RelationshipTable::relTypePair, bool> map;
	map.insert(relTable.createPair(SYNONYM_STMT, SYNONYM_ASSIGN));
	map.insert(relTable.createPair(SYNONYM_ASSIGN, SYNONYM_STMT));
	map.insert(relTable.createPair(SYNONYM_STMT, SYNONYM_STMT));
	map.insert(relTable.createPair(SYNONYM_ASSIGN, SYNONYM_ASSIGN));
	relTable.insertValidRelationsForType(FOLLOWS, map);
	relTable.insertValidRelationsForType(FOLLOWS_STAR, map);

	// Test isValidArgument function
	CPPUNIT_ASSERT(true == relTable.isValidArgument(FOLLOWS, SYNONYM_STMT, SYNONYM_ASSIGN));
	CPPUNIT_ASSERT(true == relTable.isValidArgument(FOLLOWS, SYNONYM_ASSIGN, SYNONYM_ASSIGN));
	CPPUNIT_ASSERT(true == relTable.isValidArgument(FOLLOWS, SYNONYM_STMT, SYNONYM_STMT));
	CPPUNIT_ASSERT(true == relTable.isValidArgument(FOLLOWS, SYNONYM_ASSIGN, SYNONYM_STMT));
	CPPUNIT_ASSERT(false == relTable.isValidArgument(FOLLOWS, SYNONYM_VARIABLE, SYNONYM_STMT));

	CPPUNIT_ASSERT(true == relTable.isValidArgument(FOLLOWS_STAR, SYNONYM_STMT, SYNONYM_ASSIGN));
	CPPUNIT_ASSERT(true == relTable.isValidArgument(FOLLOWS_STAR, SYNONYM_ASSIGN, SYNONYM_ASSIGN));
	CPPUNIT_ASSERT(true == relTable.isValidArgument(FOLLOWS_STAR, SYNONYM_STMT, SYNONYM_STMT));
	CPPUNIT_ASSERT(true == relTable.isValidArgument(FOLLOWS_STAR, SYNONYM_ASSIGN, SYNONYM_STMT));
	CPPUNIT_ASSERT(false == relTable.isValidArgument(FOLLOWS_STAR, SYNONYM_VARIABLE, SYNONYM_STMT));

}

